<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the use of the GNU compilers.

Copyright (C) 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Standards (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Standards (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Standards (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html" rel="up" title="Top">
<link href="Invoking-GCC.html" rel="next" title="Invoking GCC">
<link href="G_002b_002b-and-GCC.html" rel="prev" title="G++ and GCC">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en_US">
<span id="Standards"></span><div class="header">
<p>
Next: <a href="Invoking-GCC.html" accesskey="n" rel="next">Invoking GCC</a>, Previous: <a href="G_002b_002b-and-GCC.html" accesskey="p" rel="prev">G++ and GCC</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Language-Standards-Supported-by-GCC"></span><h2 class="chapter">2 Language Standards Supported by GCC</h2>

<p>For each language compiled by GCC for which there is a standard, GCC
attempts to follow one or more versions of that standard, possibly
with some exceptions, and possibly with some extensions.
</p>
<span id="C-Language"></span><h3 class="section">2.1 C Language</h3>
<span id="index-C-standard"></span>
<span id="index-C-standards"></span>
<span id="index-ANSI-C-standard"></span>
<span id="index-ANSI-C"></span>
<span id="index-ANSI-C89"></span>
<span id="index-C89"></span>
<span id="index-ANSI-X3_002e159_002d1989"></span>
<span id="index-X3_002e159_002d1989"></span>
<span id="index-ISO-C-standard"></span>
<span id="index-ISO-C"></span>
<span id="index-ISO-C90"></span>
<span id="index-ISO_002fIEC-9899"></span>
<span id="index-ISO-9899"></span>
<span id="index-C90"></span>
<span id="index-ISO-C94"></span>
<span id="index-C94"></span>
<span id="index-ISO-C95"></span>
<span id="index-C95"></span>
<span id="index-ISO-C99"></span>
<span id="index-C99"></span>
<span id="index-ISO-C9X"></span>
<span id="index-C9X"></span>
<span id="index-ISO-C11"></span>
<span id="index-C11"></span>
<span id="index-ISO-C1X"></span>
<span id="index-C1X"></span>
<span id="index-ISO-C17"></span>
<span id="index-C17"></span>
<span id="index-ISO-C2X"></span>
<span id="index-C2X"></span>
<span id="index-Technical-Corrigenda"></span>
<span id="index-TC1"></span>
<span id="index-Technical-Corrigendum-1"></span>
<span id="index-TC2"></span>
<span id="index-Technical-Corrigendum-2"></span>
<span id="index-TC3"></span>
<span id="index-Technical-Corrigendum-3"></span>
<span id="index-AMD1"></span>
<span id="index-freestanding-implementation"></span>
<span id="index-freestanding-environment"></span>
<span id="index-hosted-implementation"></span>
<span id="index-hosted-environment"></span>
<span id="index-_005f_005fSTDC_005fHOSTED_005f_005f"></span>

<span id="index-std"></span>
<span id="index-ansi"></span>
<span id="index-pedantic"></span>
<span id="index-pedantic_002derrors"></span>
<p>The original ANSI C standard (X3.159-1989) was ratified in 1989 and
published in 1990.  This standard was ratified as an ISO standard
(ISO/IEC 9899:1990) later in 1990.  There were no technical
differences between these publications, although the sections of the
ANSI standard were renumbered and became clauses in the ISO standard.
The ANSI
standard, but not the ISO standard, also came with a Rationale
document.  
This standard, in both its forms, is commonly known as <em>C89</em>, or
occasionally as <em>C90</em>, from the dates of ratification.
To select this standard in GCC, use one of the options
<samp>-ansi</samp>, <samp>-std=c90</samp> or <samp>-std=iso9899:1990</samp>; to obtain
all the diagnostics required by the standard, you should also specify
<samp>-pedantic</samp> (or <samp>-pedantic-errors</samp> if you want them to be
errors rather than warnings).  See <a href="C-Dialect-Options.html">Options
Controlling C Dialect</a>.
</p>
<p>Errors in the 1990 ISO C standard were corrected in two Technical
Corrigenda published in 1994 and 1996.  GCC does not support the
uncorrected version.
</p>
<p>An amendment to the 1990 standard was published in 1995.  This
amendment added digraphs and <code>__STDC_VERSION__</code> to the language,
but otherwise concerned the library.  This amendment is commonly known
as <em>AMD1</em>; the amended standard is sometimes known as <em>C94</em> or
<em>C95</em>.  To select this standard in GCC, use the option
<samp>-std=iso9899:199409</samp> (with, as for other standard versions,
<samp>-pedantic</samp> to receive all required diagnostics).
</p>
<p>A new edition of the ISO C standard was published in 1999 as ISO/IEC
9899:1999, and is commonly known as <em>C99</em>.  (While in
development, drafts of this standard version were referred to as
<em>C9X</em>.)  GCC has substantially
complete support for this standard version; see
<a href="https://gcc.gnu.org/c99status.html">https://gcc.gnu.org/c99status.html</a> for details.  To select this
standard, use <samp>-std=c99</samp> or <samp>-std=iso9899:1999</samp>.  
</p>
<p>Errors in the 1999 ISO C standard were corrected in three Technical
Corrigenda published in 2001, 2004 and 2007.  GCC does not support the
uncorrected version.
</p>
<p>A fourth version of the C standard, known as <em>C11</em>, was published
in 2011 as ISO/IEC 9899:2011.  (While in development, drafts of this
standard version were referred to as <em>C1X</em>.)
GCC has substantially complete support
for this standard, enabled with <samp>-std=c11</samp> or
<samp>-std=iso9899:2011</samp>.  A version with corrections integrated was
prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is
known as <em>C17</em> and is supported with <samp>-std=c17</samp> or
<samp>-std=iso9899:2017</samp>; the corrections are also applied with
<samp>-std=c11</samp>, and the only difference between the options is the
value of <code>__STDC_VERSION__</code>.
</p>
<p>A further version of the C standard, known as <em>C2X</em>, is under
development; experimental and incomplete support for this is enabled
with <samp>-std=c2x</samp>.
</p>
<p>By default, GCC provides some extensions to the C language that, on
rare occasions conflict with the C standard.  See <a href="C-Extensions.html">Extensions to the C Language Family</a>.  
Some features that are part of the C99 standard
are accepted as extensions in C90 mode, and some features that are part
of the C11 standard are accepted as extensions in C90 and C99 modes.
Use of the
<samp>-std</samp> options listed above disables these extensions where
they conflict with the C standard version selected.  You may also
select an extended version of the C language explicitly with
<samp>-std=gnu90</samp> (for C90 with GNU extensions), <samp>-std=gnu99</samp>
(for C99 with GNU extensions) or <samp>-std=gnu11</samp> (for C11 with GNU
extensions).  
</p>
<p>The default, if no C language dialect options are given,
is <samp>-std=gnu17</samp>.
</p>
<p>The ISO C standard defines (in clause 4) two classes of conforming
implementation.  A <em>conforming hosted implementation</em> supports the
whole standard including all the library facilities; a <em>conforming
freestanding implementation</em> is only required to provide certain
library facilities: those in <code>&lt;float.h&gt;</code>, <code>&lt;limits.h&gt;</code>,
<code>&lt;stdarg.h&gt;</code>, and <code>&lt;stddef.h&gt;</code>; since AMD1, also those in
<code>&lt;iso646.h&gt;</code>; since C99, also those in <code>&lt;stdbool.h&gt;</code> and
<code>&lt;stdint.h&gt;</code>; and since C11, also those in <code>&lt;stdalign.h&gt;</code>
and <code>&lt;stdnoreturn.h&gt;</code>.  In addition, complex types, added in C99, are not
required for freestanding implementations.  
</p>
<p>The standard also defines two environments for programs, a
<em>freestanding environment</em>, required of all implementations and
which may not have library facilities beyond those required of
freestanding implementations, where the handling of program startup
and termination are implementation-defined; and a <em>hosted
environment</em>, which is not required, in which all the library
facilities are provided and startup is through a function <code>int
main (void)</code> or <code>int main (int, char *[])</code>.  An OS kernel is an example
of a program running in a freestanding environment; 
a program using the facilities of an
operating system is an example of a program running in a hosted environment.
</p>
<span id="index-ffreestanding"></span>
<p>GCC aims towards being usable as a conforming freestanding
implementation, or as the compiler for a conforming hosted
implementation.  By default, it acts as the compiler for a hosted
implementation, defining <code>__STDC_HOSTED__</code> as <code>1</code> and
presuming that when the names of ISO C functions are used, they have
the semantics defined in the standard.  To make it act as a conforming
freestanding implementation for a freestanding environment, use the
option <samp>-ffreestanding</samp>; it then defines
<code>__STDC_HOSTED__</code> to <code>0</code> and does not make assumptions about the
meanings of function names from the standard library, with exceptions
noted below.  To build an OS kernel, you may well still need to make
your own arrangements for linking and startup.
See <a href="C-Dialect-Options.html">Options Controlling C Dialect</a>.
</p>
<p>GCC does not provide the library facilities required only of hosted
implementations, nor yet all the facilities required by C99 of
freestanding implementations on all platforms.  
To use the facilities of a hosted
environment, you need to find them elsewhere (for example, in the
GNU C library).  See <a href="Standard-Libraries.html">Standard Libraries</a>.
</p>
<p>Most of the compiler support routines used by GCC are present in
<samp>libgcc</samp>, but there are a few exceptions.  GCC requires the
freestanding environment provide <code>memcpy</code>, <code>memmove</code>,
<code>memset</code> and <code>memcmp</code>.
Finally, if <code>__builtin_trap</code> is used, and the target does
not implement the <code>trap</code> pattern, then GCC emits a call
to <code>abort</code>.
</p>
<p>For references to Technical Corrigenda, Rationale documents and
information concerning the history of C that is available online, see
<a href="https://gcc.gnu.org/readings.html">https://gcc.gnu.org/readings.html</a>
</p>
<span id="C_002b_002b-Language"></span><h3 class="section">2.2 C++ Language</h3>

<p>GCC supports the original ISO C++ standard published in 1998,
and the 2011, 2014, 2017 and mostly 2020 revisions.
</p>
<p>The original ISO C++ standard was published as the ISO standard (ISO/IEC
14882:1998) and amended by a Technical Corrigenda published in 2003
(ISO/IEC 14882:2003). These standards are referred to as C++98 and
C++03, respectively. GCC implements the majority of C++98 (<code>export</code>
is a notable exception) and most of the changes in C++03.  To select
this standard in GCC, use one of the options <samp>-ansi</samp>,
<samp>-std=c++98</samp>, or <samp>-std=c++03</samp>; to obtain all the diagnostics
required by the standard, you should also specify <samp>-pedantic</samp> (or
<samp>-pedantic-errors</samp> if you want them to be errors rather than
warnings).
</p>
<p>A revised ISO C++ standard was published in 2011 as ISO/IEC
14882:2011, and is referred to as C++11; before its publication it was
commonly referred to as C++0x.  C++11 contains several changes to the
C++ language, all of which have been implemented in GCC. For details
see <a href="https://gcc.gnu.org/projects/cxx-status.html#cxx11">https://gcc.gnu.org/projects/cxx-status.html#cxx11</a>.
To select this standard in GCC, use the option <samp>-std=c++11</samp>.
</p>
<p>Another revised ISO C++ standard was published in 2014 as ISO/IEC
14882:2014, and is referred to as C++14; before its publication it was
sometimes referred to as C++1y.  C++14 contains several further
changes to the C++ language, all of which have been implemented in GCC.
For details see <a href="https://gcc.gnu.org/projects/cxx-status.html#cxx14">https://gcc.gnu.org/projects/cxx-status.html#cxx14</a>.
To select this standard in GCC, use the option <samp>-std=c++14</samp>.
</p>
<p>The C++ language was further revised in 2017 and ISO/IEC 14882:2017 was
published.  This is referred to as C++17, and before publication was
often referred to as C++1z.  GCC supports all the changes in that
specification.  For further details see
<a href="https://gcc.gnu.org/projects/cxx-status.html#cxx17">https://gcc.gnu.org/projects/cxx-status.html#cxx17</a>.  Use the option
<samp>-std=c++17</samp> to select this variant of C++.
</p>
<p>Another revised ISO C++ standard was published in 2020 as ISO/IEC
14882:2020, and is referred to as C++20; before its publication it was
sometimes referred to as C++2a.  GCC supports most of the changes in the
new specification.  For further details see
<a href="https://gcc.gnu.org/projects/cxx-status.html#cxx20">https://gcc.gnu.org/projects/cxx-status.html#cxx20</a>.
To select this standard in GCC, use the option <samp>-std=c++20</samp>.
</p>
<p>More information about the C++ standards is available on the ISO C++
committee&rsquo;s web site at <a href="http://www.open-std.org/jtc1/sc22/wg21/">http://www.open-std.org/jtc1/sc22/wg21/</a>.
</p>
<p>To obtain all the diagnostics required by any of the standard versions
described above you should specify <samp>-pedantic</samp>
or <samp>-pedantic-errors</samp>, otherwise GCC will allow some non-ISO C++
features as extensions. See <a href="Warning-Options.html">Warning Options</a>.
</p>
<p>By default, GCC also provides some additional extensions to the C++ language
that on rare occasions conflict with the C++ standard.  See <a href="C_002b_002b-Dialect-Options.html">Options Controlling C++ Dialect</a>.  Use of the
<samp>-std</samp> options listed above disables these extensions where they
they conflict with the C++ standard version selected.  You may also
select an extended version of the C++ language explicitly with
<samp>-std=gnu++98</samp> (for C++98 with GNU extensions), or
<samp>-std=gnu++11</samp> (for C++11 with GNU extensions), or
<samp>-std=gnu++14</samp> (for C++14 with GNU extensions), or
<samp>-std=gnu++17</samp> (for C++17 with GNU extensions), or
<samp>-std=gnu++20</samp> (for C++20 with GNU extensions).
</p>
<p>The default, if
no C++ language dialect options are given, is <samp>-std=gnu++17</samp>.
</p>
<span id="Objective_002dC-and-Objective_002dC_002b_002b-Languages"></span><h3 class="section">2.3 Objective-C and Objective-C++ Languages</h3>
<span id="index-Objective_002dC-1"></span>
<span id="index-Objective_002dC_002b_002b-1"></span>

<p>GCC supports &ldquo;traditional&rdquo; Objective-C (also known as &ldquo;Objective-C
1.0&rdquo;) and contains support for the Objective-C exception and
synchronization syntax.  It has also support for a number of
&ldquo;Objective-C 2.0&rdquo; language extensions, including properties, fast
enumeration (only for Objective-C), method attributes and the
@optional and @required keywords in protocols.  GCC supports
Objective-C++ and features available in Objective-C are also available
in Objective-C++.
</p>
<p>GCC by default uses the GNU Objective-C runtime library, which is part
of GCC and is not the same as the Apple/NeXT Objective-C runtime
library used on Apple systems.  There are a number of differences
documented in this manual.  The options <samp>-fgnu-runtime</samp> and
<samp>-fnext-runtime</samp> allow you to switch between producing output
that works with the GNU Objective-C runtime library and output that
works with the Apple/NeXT Objective-C runtime library.
</p>
<p>There is no formal written standard for Objective-C or Objective-C++.
The authoritative manual on traditional Objective-C (1.0) is
&ldquo;Object-Oriented Programming and the Objective-C Language&rdquo;:
<a href="https://gnustep.github.io/resources/documentation/ObjectivCBook.pdf">https://gnustep.github.io/resources/documentation/ObjectivCBook.pdf</a>
is the original NeXTstep document.
</p>
<p>The Objective-C exception and synchronization syntax (that is, the
keywords <code>@try</code>, <code>@throw</code>, <code>@catch</code>,
<code>@finally</code> and <code>@synchronized</code>) is
supported by GCC and is enabled with the option
<samp>-fobjc-exceptions</samp>.  The syntax is briefly documented in this
manual and in the Objective-C 2.0 manuals from Apple.
</p>
<p>The Objective-C 2.0 language extensions and features are automatically
enabled; they include properties (via the <code>@property</code>,
<code>@synthesize</code> and
<code>@dynamic keywords</code>), fast enumeration (not available in
Objective-C++), attributes for methods (such as <code>deprecated</code>,
<code>noreturn</code>, <code>sentinel</code>, <code>format</code>),
the <code>unused</code> attribute for method arguments, the
<code>@package</code> keyword for instance variables and the <code>@optional</code> and
<code>@required</code> keywords in protocols.  You can disable all these
Objective-C 2.0 language extensions with the option
<samp>-fobjc-std=objc1</samp>, which causes the compiler to recognize the
same Objective-C language syntax recognized by GCC 4.0, and to produce
an error if one of the new features is used.
</p>
<p>GCC has currently no support for non-fragile instance variables.
</p>
<p>The authoritative manual on Objective-C 2.0 is available from Apple:
</p><ul>
<li> <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html">https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html</a>
</li></ul>

<p>For more information concerning the history of Objective-C that is
available online, see <a href="https://gcc.gnu.org/readings.html">https://gcc.gnu.org/readings.html</a>
</p>
<span id="Go-Language"></span><h3 class="section">2.4 Go Language</h3>

<p>As of the GCC 4.7.1 release, GCC supports the Go 1 language standard,
described at <a href="https://go.dev/doc/go1">https://go.dev/doc/go1</a>.
</p>
<span id="D-language"></span><h3 class="section">2.5 D language</h3>

<p>GCC supports the D 2.0 programming language.  The D language itself is
currently defined by its reference implementation and supporting language
specification, described at <a href="https://dlang.org/spec/spec.html">https://dlang.org/spec/spec.html</a>.
</p>
<span id="References-for-Other-Languages"></span><h3 class="section">2.6 References for Other Languages</h3>

<p>See <a href="https://gcc.gnu.org/onlinedocs/gnat_rm/index.html#Top">About This Guide</a> in <cite>GNAT Reference Manual</cite>, for information on standard
conformance and compatibility of the Ada compiler.
</p>
<p>See <a href="https://gcc.gnu.org/onlinedocs/gfortran/Standards.html#Standards">Standards</a> in <cite>The GNU Fortran Compiler</cite>, for details
of standards supported by GNU Fortran.
</p>

<hr>
<div class="header">
<p>
Next: <a href="Invoking-GCC.html" accesskey="n" rel="next">Invoking GCC</a>, Previous: <a href="G_002b_002b-and-GCC.html" accesskey="p" rel="prev">G++ and GCC</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
